I currently have this .htaccess code to remove .php/.html extensions.
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
# End of Apache Rewrite Rules
</IfModule>
I am trying to have a page poll.php to be /poll/123123/ <- (6 digit ID) from poll.php?poll=123123.
I tried adding in
RewriteRule ^[A-Za-z0-9-]+/([A-Za-z0-9-]+)/?$ polls.php?poll=$1 [NC,L]
but it then tries to detect dashboard.php instead of dashboard.html.
Any help would be appreciated, thanks.
There is no need for a wildcard if you're looking for a sp[ecific URL and only the number changes
RewriteRule ^poll/(\d+)/$ polls.php?poll=$1
or better to get always 6 digits
RewriteRule ^poll/([0-9]{6})/$ polls.php?poll=$1
That should do
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.