LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Rewrite URL in apache (https://www.linuxquestions.org/questions/linux-server-73/rewrite-url-in-apache-4175429726/)

trickynapzter 09-30-2012 08:05 AM

Rewrite URL in apache
 
Hi all, can i ask for your help? I'm in trouble in setting up my vhost in apache. Currently my site is up and running, my problem is that I can't get it to short url. Here's the scenario:

a. I have a website running on my server currently on vhost on port 80 and 443. Here is the config file:

Code:

    <VirtualHost *:80>
        ServerName wiki.company.com
        ServerAdmin infra@company.com
        ServerAlias wiki wiki.company.com

        DocumentRoot /var/www/html

        Redirect / https://wiki.company.com/

    </VirtualHost>

    <VirtualHost *:443>
        ServerName wiki.company.com
        ServerAdmin infra@company.com

        ProxyPreserveHost On
        ProxyRequests Off
        SSLProxyEngine off
        SSLEngine on
        SSLProtocol -ALL +SSLv3 +TLSv1
        SSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/pki/tls/certs/server.crt
        SSLCertificateKeyFile /etc/pki/tls/certs/server.key

        DocumentRoot /var/www/html
        RedirectMatch ^/$ /wiki/

      ##################################
        RewriteEngine On
        RewriteRule ^/?view(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L]
        RewriteRule ^/?$ %{DOCUMENT_ROOT}/wiki/index.php [L]
      ##################################
      <Directory /var/www/html/wiki>
            Options Indexes FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>

    </VirtualHost>

b. Whenever i am going to visit the login page which is https://wiki.company.com/view/Special:UserLogin. I want to rewrite it's URL to display only https://wiki.company.com/login or just https://wiki.company.com/. But my RewriteRule fails. This is what i have added to :*443

Code:

RewriteRule ^/view/Special:UserLogin(.*) https://wiki.company.com/ [R,L]
Hope i explain myself clearly on this. Thanks

bathory 09-30-2012 09:21 AM

Hi,
Quote:

b. Whenever i am going to visit the login page which is https://wiki.company.com/view/Special:UserLogin. I want to rewrite it's URL to display only https://wiki.company.com/login or just https://wiki.company.com/. But my RewriteRule fails. This is what i have added to :*443
I don't know how it's failing, but please note that you have another rule:
Quote:

RewriteRule ^/?view(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L]
that rewrites a URL starting with "/view..." to "/var/www/html/wiki/index.html"

Regards

deep27ak 10-01-2012 07:14 AM

you can add an alias entry for view/Special:UserLogin

Code:

Alias  /    view/Special:UserLogin
or
Code:

Alias  /login    view/Special:UserLogin
restart your apache server

bathory 10-01-2012 07:58 AM

Quote:

Originally Posted by deep27ak (Post 4793914)
you can add an alias entry for view/Special:UserLogin

Code:

Alias  /    view/Special:UserLogin
or
Code:

Alias  /login    view/Special:UserLogin
restart your apache server

No you can't.
Alias is used to map a directory outside the DocumentRoot to some URL. In this case Special:UserLogin surely does not look like a directory name, so you cannot alias it to something else.

_dkode_ 10-01-2012 03:51 PM

bathory pointed out the issue,
adding a Rewrite Condition before the ambiguous Rewrite Rule will solve the issue.
Quote:

RewriteCond %{REQUEST_URI} !^/view/Special:UserLogin
RewriteRule ^/?view(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L]


All times are GMT -5. The time now is 04:37 PM.