PDA

View Full Version : سوال: زیبا سازی url - شبیه CodeIgniter و یا WP



AbiriAmir
جمعه 05 خرداد 1391, 18:04 عصر
سلام دوستان
من تا الان تو پروژه هام برای زیبا کردن url ها و seo از mod_rewrite استفاده میکردم
مثلا میگم:
www.site.com/contents/iran
این صفحه رو لود کنه:
www.site.com/index.php?module=contents&title=iran

اما الان میخوام ببینم دو سیستم زیر چجوری کار میکنن؟

CodeIgniter
Wordpress

CI رو همین الان دانلود کردم و تجربه کار باهاشو ندارم اما تو userguide که نوشته شده بود اینجوری هست:
www.site.com/index.php/class/function/id

حالا من میخوام سیستمی رو مشابه یکی از دو مورد بالا ایجاد کنم
یعنی با mod_rewrite نمیخوام کار کنم (البته منظورم مثل قبل هست نه مثلا مثل وردپرس)

حالا میخوام ببینم wp یا ci کدهای php شون چجوری هست؟

الان مثلا من میخوام 1 سیستم بلاگ دهی بنویسم
مثلا این ها بلاگ ها هستن:
www.site.com/blog1
www.site.com/blog2
www.site.com/blog3
و ...

و مثلا این گالری خود سایت هست:
www.site.com/gallery/id

(منظورم اینه که هر چیزی که بعد از سایت میاد هم مربوط به وبلاگ نمیشه)

حالا میخوام ببینم این رو چجوری باید پیاده کنم...
ممنون

eshpilen
جمعه 05 خرداد 1391, 18:51 عصر
CI رو همین الان دانلود کردم و تجربه کار باهاشو ندارم اما تو userguide که نوشته شده بود اینجوری هست:
www.site.com/index.php/class/function/id (http://www.site.com/index.php/class/function/id)

حالا من میخوام سیستمی رو مشابه یکی از دو مورد بالا ایجاد کنم
یعنی با mod_rewrite نمیخوام کار کنم (البته منظورم مثل قبل هست نه مثلا مثل وردپرس)

والا تاجاییکه بنده میدونم بعد از اسم فایل PHP که اسلش بیاد و بعدش اطلاعات دیگه، این اطلاعات اضافه در آرایهء $_SERVER در PATH_INFO قابل دسترسی هست. البته در چندتا متغییر دیگر هم که حاوی آدرس خود فایل هم هستن پیدا میشه.

لابد این نرم افزارها هم این اطلاعات رو میگیرن و خودشون Parse و تحلیل میکنن.

خلاصه اینو یه بررسی بکن:


$_SERVER['PATH_INFO']

AbiriAmir
جمعه 05 خرداد 1391, 23:00 عصر
ممنون از شما
بله
1چیزایی پیدا کردم:
http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/#post-comments

webiran.co
شنبه 06 خرداد 1391, 11:49 صبح
خب، اگر اطلاعات دقیقی درباره URL rewrite بخواهی من قبلا یک مقاله درموردش نوشتم، که می توانی بخوانی
ولی در مورد wordpress، یک ماژول کامل برای اینکار دارد، که می‌توانی نوع نمایش بازنویسی مسیرها را مشخص کنی
توی این مقاله http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/ البته انگلیسی اطلاعات بیشتری در موردش هست.

AbiriAmir
یک شنبه 07 خرداد 1391, 11:32 صبح
خب، اگر اطلاعات دقیقی درباره URL rewrite بخواهی من قبلا یک مقاله درموردش نوشتم، که می توانی بخوانی
ولی در مورد wordpress، یک ماژول کامل برای اینکار دارد، که می‌توانی نوع نمایش بازنویسی مسیرها را مشخص کنی
توی این مقاله http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/ البته انگلیسی اطلاعات بیشتری در موردش هست.
مقاله خود من را هم می‌توانی اینجا بخونی http://www.webiran.co/Articles/

ممنون از مقالتون اما همینطوری که عرض کردم تا الان از rewrite استفاده میکردم اما الان مثلا میخوام دیگه www.site.com/article/1 نشه بلکه مثله بشه www.site.com/1

فعلا دارم مقاله هایی در مورد url routing میخونم

AbiriAmir
یک شنبه 07 خرداد 1391, 11:37 صبح
این تیکش خیلی به دردم خورد:



FILE EXISTENCE AND WORDPRESS
Smashing Magazine runs on the popular blogging software WordPress. WordPress enables the author to choose their own URL, called a “slug.” Then, it automatically prepends the date, such as http://coding.smashingmagazine.com/2011/09/05/getting-started-with-the-paypal-api/. In your pre-URL rewriting days, you might have assumed that Smashing Magazine’s Web server was actually serving up a file located at …/2011/09/05/getting-started-with-the-paypal-api/index.html. In fact, WordPress uses URL rewriting extensively.

WordPress enables the author to choose their own URL for an article.
WordPress’ .htaccess file looks like this:
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
The -f means “this is a file” and -d means “this is a directory.” This tells Apache, if the requested file name is not a file, and the requested file name is not a directory, then rewrite everything (i.e. any path containing any character) to the page index.php. If you are requesting an existing image or the log-in page wp-login.php, then the rule is not triggered. But if you request anything else, like /2011/09/05/getting-started-with-the-paypal-api/, then the file index.php jumps into action.
Internally, index.php (probably) looks at the environment variable $_SERVER['REQUEST_URI'] and extracts the information that it needs to find out what it is looking for. This gives it even more flexibility than Apache’s rewrite rules and enables WordPress to mimic some very sophisticated URL rewriting rules. In fact, when administering a WordPress blog, you can go to Settings → Permalink on the left side, and choose the type of URL rewriting that you would like to mimic.

WordPress’ permalink settings, letting you choose the type of URL rewriting that you would like to mimic.

plague
یک شنبه 07 خرداد 1391, 13:19 عصر
ci خودش url ها رو پارس میکنه
من با بقیه فریم ورک ها آشنا نیستم ولی فکر میکنم همه فریم ورک های mvc از مکانیسم مشابهی استفاده میکنن
اگه میخاید میتونید این کتاب رو مطالعه کنید سیستم پارسر رو تا اونجا که یادمه توضیح داده بود

http://www.amazon.com/PHP-Social-Networking-Michael-Peacock/dp/1849512388/
کتاب بسیار بد نوشته شده ولی اطلاعات ارزشمندی توش میشه پیدا کرد از جمله ساخت یک فریم ورک mvc از پایه
من که تا صفحه 50 رو بیشتر نتونستم بخونم !!