RewriteRule

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
henriksw
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Jun 05, 2018 10:52 pm

Sun Jun 17, 2018 11:10 am

I'm using a Rewriterule as

Code: Select all

RewriteRule ^start/([0-9a-zA-Z_-]+) index.php?val=$1
which works fine. val can be a string as "show-page-1" for example. The url then becomes

site.com/start/show-page-1

I want the url to be shown without /start as

site.com/show-page-1

Is this possible?

chorn
php-forum Fan User
php-forum Fan User
Posts: 551
Joined: Fri Apr 01, 2016 2:18 am

Sun Jun 17, 2018 9:39 pm

Did you really not even try anything like just removing the parts you do not want to match within the URL?

henriksw
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Jun 05, 2018 10:52 pm

Mon Jun 18, 2018 6:39 am

chorn wrote:
Sun Jun 17, 2018 9:39 pm
Did you really not even try anything like just removing the parts you do not want to match within the URL?
Tried to just remove start/ and the url becomes what I aim for. But the value I get from $_GET['val'] becomes "index".

chorn
php-forum Fan User
php-forum Fan User
Posts: 551
Joined: Fri Apr 01, 2016 2:18 am

Mon Jun 18, 2018 9:37 pm

your rewrite rule is missing the terminator at the end.

henriksw
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Jun 05, 2018 10:52 pm

Sun Jun 24, 2018 5:57 am

Having problem adding the R=301 for permanent redirect. The code is shown below which is working fine. If I add R=301 after [L], the requested URL can not be found. Anybody know why?

Code: Select all

RewriteEngine On
RewriteRule ^page/([0-9a-zA-Z_-]+)$ page.php?c=$1 [L]

Post Reply