رفتن به مطلب

مشکل ساده با پست ها و htaccess


پست های پیشنهاد شده

سلام

تشکر بابت انجمن واقعا مشکلاتم خیلی زود برطرف شدن

من از یک سیستم استفاده میکنم که به صورت معمولی به این صورت پست هاش نمایش داده میشه


www.site.com/56985_نام-پست.html

این کدهاش در فایل function.php برای معرفی عنوان مطلب به اون شکل هست:


$str = $C->URL . $type . "/" . $id . "_" . $title . ".html" ;

من تغییرش دادم و به این صورت کردم :


$str = $C->URL . $type . "/" . $title . ".html" ;

پست ها لینکاشون در سایت درست میشه و به این شکل میشن :


www.site.com/نام-پست.html

اما به مطلب که میری خطای 404 میده و مطلب رو نمایش نمیده

ولی اگر مطلب را به صورت این شکلی وارد کنی کار میکنه و مطلب رو میاره


www.site.com/article197105.html

کدهای htaccess سایت هم اینه :



#AddDefaultCharset utf-8
#php_flag display_errors 0
#php_flag magic_quotes_gpc Off

Options +FollowSymlinks
RewriteEngine On
DirectoryIndex index.php index.html

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*) http://%1/$1 [L,R=302]

RewriteRule ^tags/(.+)/page/([0-9]+)/?$ index.php?act=search&tag=$1&page=$2 [QSA,NC,L]
RewriteRule ^tags/(.+)/?\.html$ index.php?act=search&tag=$1 [QSA,NC,L]
RewriteRule ^tags/(.+)/?$ index.php?act=search&tag=$1 [QSA,NC,L]

RewriteRule ^rss/([0-9]+)/(.+)/(.+)/?(\.xml)?$ rss.php?cat=$1 [QSA,NC,L]
RewriteRule ^rss/([0-9]+)/?(.+)?/?(\.xml)?$ rss.php?id=$1 [QSA,NC,L]
RewriteRule ^sitemap.xml/?$ sitemap.php [QSA,NC,L]
RewriteRule ^sitemap2.xml/?$ sitemap2.php [QSA,NC,L]

RewriteRule ^(.+)/([0-9]+)/(.+)/?\.html$ /$1/article$2.html [L,R=301]
RewriteRule ^([0-9]+)/(.+)/?\.html$ /post/article$1.html [L,R=301]
RewriteRule ^(.+)/([0-9]+)_(.+)/?$ /$1/article$2.html [L,R=301]
RewriteRule ^(.+)/article(.+)/?\.html$ index.php?act=$1&id=$2 [QSA,NC,L]

RewriteRule ^cat/([0-9]+)/page/([0-9]+)/?$ index.php?cat=$1&page=$2 [QSA,NC,L]
RewriteRule ^cat/([0-9]+)/(.+)/?\.php$ index.php?cat=$1 [QSA,NC,L]
RewriteRule ^subcat/(.+)/page/([0-9]+)/?$ index.php?catname=$1&page=$2 [QSA,NC,L]
#RewriteRule ^link\.php\?id=([0-9]+)/?$ index.php?id=$1 [QSA,NC,L]

## SubCat's
RewriteRule ^subcat/(.+)/(.+)/page/(.+)/?$ index.php?error=1&subcat=$1&catname=$2&page=$3 [QSA,NC,L]
RewriteRule ^subcat/(.+)/(.+)/?$ index.php?error=1&subcat=$1&catname=$2 [QSA,NC,L]
## SubCat's

## Cat's
RewriteRule ^cat/(.+)/page/(.+)/?$ index.php?error=1&subcat=$1&page=$2 [QSA,NC,L]
RewriteRule ^cat/(.+)/?$ index.php?error=1&subcat=$1 [QSA,NC,L]
## Cat's

RewriteCond %{REQUEST_FILENAME} "!admin/(.*)"
RewriteCond %{REQUEST_FILENAME} "!google(.*)"
RewriteRule ^(.+)/?\.html$ index.php?catname=$1 [QSA,NC,L]
RewriteRule ^page/(.+).php$ index.php?act=page&page=$1 [QSA,NC,L]

## Search ##
#RewriteRule ^items/(.+)/?\.html$ index.php?act=search&tag=$1 [QSA,NC,L]
#RewriteRule ^search/(.+)/?\.html$ index.php?act=search&tag=$1 [QSA,NC,L]

RewriteRule ^(.+)/([0-9]+)/(.+)/?\.html$ index.php?act=$1&id=$2&name=$3 [QSA,NC,L]
RewriteRule ^(.+)/([0-9]+)/?\.html$ index.php?act=$1&id=$2 [QSA,NC,L]
RewriteRule ^(.+)/([0-9]+)_(.+)/?$ index.php?id=$2&title=$3 [QSA,NC,L]

RewriteRule ^([0-9]+)_(.+)/?$ index.php?id=$1&title=$2 [QSA,NC,L]
#RewriteRule ^([0-9]+)_(.+)/?$ index.php?tag=$2 [QSA,NC,L]

RewriteRule ^(.+)/(.+)/page/([0-9]+)/?$ index.php?$1=$2&page=$3 [QSA,NC,L]
RewriteRule ^(.+)?/?page/([0-9]+)/?$ index.php?act=$1&page=$2 [QSA,NC,L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|png|bmp) /userfiles/nopic.jpg [NC,L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^(.+) index.php?error=404 [NC,L]

#AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent


<FilesMatch ".*$">
ErrorDocument 404 /index.php?error=404
ErrorDocument 400 /index.php?error=400
ErrorDocument 500 /index.php?error=500
</FilesMatch>

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|jpg|png|gif)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

AddType application/octet-stream mp3
AddType application/octet-stream mp4
AddType application/octet-stream 3gp
AddType application/octet-stream mpg
AddType application/octet-stream mpeg

<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=864000, public"
</FilesMatch>

<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=3600, public, must-revalidate"
</FilesMatch>

<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
<LimitExcept POST GET>
</LimitExcept>

میدونم مشکل سادست ولی هر کاری میکنم درست نمیشه

ممنون میشم راهنمائی کنید

ویرایش شده توسط beh9am
لینک به ارسال

سلام

دلیل استفاده از این نوع پیوند یکتا چیه؟

پیوند یکتا ؟

سیستم وردپرس نیست

مشکلم همینه که کار نمیکنه به اون شکل که عرض کردم

لینک به ارسال

خب اولا که باید یک htaccess برای این پیوند بهش اضافه کنید و اینکه کدی اضافه کنید که اونو بشناسه

مثال

RewriteRule ^([^/]+)\.html$ index.php?title=$1 [L,R=301]

لینک به ارسال

خب اولا که باید یک htaccess برای این پیوند بهش اضافه کنید و اینکه کدی اضافه کنید که اونو بشناسه

مثال

RewriteRule ^([^/]+)\.html$ index.php?title=$1 [L,R=301]

ولی ولی متاسفانه اطلاعاتم در این زمینه خیلی کمه و نمیتونم

الان من در فانکشن کدش که اینه :


$str = $C->URL . $type . '/' . $id . '_' . $title ;

تغییر میدم به این که فقط عنوان مطلب باشه وشماره نوشته حذف بشه :


$str = $C->URL . $type . '/' . $title ;

و کد شمارو داخل htaccess میزارم ولی بازم کار نمیکنه در حالت فقط عنوان

ولی به همون شکل با شماره نوشته کار میکنه

کد کامل قسمت فانکشن هم اینه :


function make_seo($type,$id,$title) {
global $C ;
if ( $C->POST_SEO == 0 ) return 'http://' . $type . '.' . $C->DOMAIN . '/' . $type . '/article' . $id . '.html' ;
if ( $C->POST_SEO == 0 ) return $C->URL . $type . '/article' . $id . '.html' ;
$title = mb_ereg_replace('[^A-Za-z0-9آ-ی \_\-]+',' ',$title);
$words = explode(' ',$title);
if ( count($words) > 15 ) {
$title = implode(' ',array_splice($words,0,15));
}
$title = str_replace('_','-',$title); $title = url_encode($title);
$str = $C->URL . $type . '/' . $id . '_' . $title ;
return $str ;
}
function makeseo($type,$id,$title) {
global $C ;
if ( $C->POST_SEO == 0 ) return $C->URL . $type . '/article' . $id . '.html' ;
if ( strlen($title) > 120 ) $title = substr($title,0,120) ;
$title = mb_ereg_replace('[^A-Za-z0-9آ-ی \_\-]+',' ',$title);
$title = str_replace("_","-",$title); $title = url_encode($title);
$str = $C->URL . $type . "/" . $id . "/" . $title . ".html" ;
//$str = $C->URL . $id . '_' . $title ; //. '.html'
return $str ;
}

فکر کنم من اشتباه انجام میدم درسته ؟

ویرایش شده توسط beh9am
لینک به ارسال

کد پرمالینک خروجی مهم نیست کد bootstrap که درون index.php هست و url رو انالیز میکنه مهم

که بتونه این تغییر جدید رو درک کنه و کاروشو انجام بده

تغییر پرمالینک و htaccess میشه نصف کار

تنظیم اینکه بیاد مقدار title رو از ادرس بگیره و پست مربوطه رو نشون بده میشه نصف دیگه کار

لینک به ارسال

کد پرمالینک خروجی مهم نیست کد bootstrap که درون index.php هست و url رو انالیز میکنه مهم

که بتونه این تغییر جدید رو درک کنه و کاروشو انجام بده

تغییر پرمالینک و htaccess میشه نصف کار

تنظیم اینکه بیاد مقدار title رو از ادرس بگیره و پست مربوطه رو نشون بده میشه نصف دیگه کار

آدرس ها در سایت درست شدن و به این شکل شدن :


site.com/نام پست

ولی باز که میکنی نمیاره

حالا اگر به این شکل وارد کنی میاره :


www.site.com/5698_نام پست

من فقط میخوام اون عدد حذف بشه که حذفش کردم ولی صفحات باز نمیشن

لینک به ارسال

فکر کنم اینو بزاری درست بشه


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

تشکر ولی وردپرس نیست !

لینک به ارسال

شما به این آموزش یه نگاهی بندازی روند کار دستت میاد و متوجه میشی کجا رو باید تغییر بدی


http://forum.codecall.net/topic/74170-clean-urls-with-php/
http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...